package com.kcsj.servelt;

import com.kcsj.model.User;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class UserLogout
 */
@WebServlet("/user_logout")
public class UserLogoutServlet extends HttpServlet {

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("user");
		request.getSession().removeAttribute("user");
		if(user.isIsadmin()) {
			request.getRequestDispatcher("/admin/index.jsp").forward(request, response);
			return;
		}
		response.sendRedirect(request.getContextPath() + "/index");
	}

}
